<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\ResourceCollection;

class BusinessCollection extends ResourceCollection
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'code' => 200,
            'message' => '请求成功',
            'data'=>$this->collection->map(function ($item){
                /**
                 * @var $item \App\Models\Business
                 */
                return [
                    'id'=>$item->id,
                    'title'=>$item->title,
                    'logo'=>\Storage::url($item->logo),
                    'type_name'=>$item->type->name,
                    'type_id'=>$item->bussine_type_id,
                    'price'=>$item->price,
                    'xiaofei'=>$item->xiaofei,
                    'chanpin'=>$item->chanpin,
                    'city'=>$item->city,
                ];
            })
        ];
    }
}
